package com.uenpay.oem.ui.auth;

import com.uenpay.oem.data.bean.UserIdCardInfo;
import com.uenpay.oem.data.model.IUserAuthModel;
import com.uenpay.oem.data.modelImpl.UserAuthModel;
import com.uenpay.util.common.PicUtil;
import com.uenpay.util.net.listener.HttpOnNextListener;

/**
 * Author: liulou
 * Date: 2017/6/18.
 * desc:
 */

public class AuthCameraPresenter implements AuthCameraContract.Presenter {

    private AuthCameraContract.View mView;
    private IUserAuthModel mUserAuthModel;

    public AuthCameraPresenter(AuthCameraContract.View view) {
        this.mView = view;
        mUserAuthModel = new UserAuthModel();
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onDestroy() {

    }

    @Override
    public void recognition(byte[] data, int type) {
        if (mUserAuthModel == null) mUserAuthModel = new UserAuthModel();
        mUserAuthModel.userRealNameImageUpload(PicUtil.byteToBase64(data), new HttpOnNextListener<UserIdCardInfo>() {

            @Override
            public void onStart() {
                super.onStart();
                mView.showLoading();
            }

            @Override
            public void onNext(UserIdCardInfo userIdCardInfo) {
                mView.dismissLoading();
                mView.showToast("识别成功");
                mView.recognitionResult(userIdCardInfo);
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
//                mView.showToast("识别失败，请重试");
                mView.remake();
            }
        });

    }
}
